package com.kgc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName CORSConfig
 * @Description TODO
 * @Author yaozhaobao
 * @Date 2019/6/13 15:23
 * @Version 1.0
 **/
@Configuration
public class CORSConfig {

    /* <bean id="corsConfigurer" class="org.springframework.web.servlet.config.annotation.WebMvcConfigurer"   */
    @Bean
    public WebMvcConfigurer corsConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                //我前端项目放在8020端口上,只有8020的服务器才能访问资源,
                // 可以改成 .allowedOrigins("*");  所有前端应用服务器都可以访问
                registry.addMapping("/**")
                        .allowedHeaders("*")
                        .allowedMethods("*")
                        .allowedOrigins("http://127.0.0.1:8020");
            }
        };
    }



}
